package com.ruoyi.project.system.picture.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.ruoyi.common.utils.LireUtil;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.picture.domain.Picture;
import com.ruoyi.project.system.picture.service.IPictureService;

@Controller
@RequestMapping("/system/picture")
public class LireController extends BaseController{
	private String prefix = "system/search";
    @Autowired
    private IPictureService pictureService;
    
    @RequiresPermissions("system:picture:lire")
    @GetMapping("/lire")
    public String lire(Model m)
    {
        return prefix + "/search";
    }
    
    @PostMapping("/lire/index")
    @ResponseBody
    public AjaxResult index() {
    	if(LireUtil.index(pictureService.selectPictureAll()))
    		return success();
    	else
    		return error();
    }
    
    
    @PostMapping("/lire/search")
    @ResponseBody
    public List<Picture> search(String type,@RequestParam("searchfile")MultipartFile file) throws IOException {
    	if(file!=null) {
    		List<Long> ids = LireUtil.search(type,file.getBytes());
    		return pictureService.selectPictures(ids);
    	}
    	return new ArrayList<Picture>();
    }
}
